home
diamond Go Premium
Data Engineering Path  ·  PySpark

PySpark RDD Execution Tracing: Clickstream Logs

Series Data Engineering & Distributed Systems Series
Estimated Time ~35 Mins Lab
Lab Objective Trace user clickstream log records step-by-step through PySpark RDD narrow transformations (`filter`, `map`), wide shuffles (`reduceByKey`), and driver action collections (`collect`).

Input Clickstream Logs & Setup

Dataset:

user1,click,home,2026-05-25T10:00:00
user2,view,product_page,2026-05-25T10:01:00
user1,click,checkout,2026-05-25T10:02:00
user3,view,home,2026-05-25T10:03:00
user1,click,payment_gateway,2026-05-25T10:04:00

PySpark Pipeline Code:

raw_rdd = sc.textFile("clickstream.txt", minPartitions=2)
clicks_rdd = raw_rdd.map(lambda line: line.split(",")) \
                    .filter(lambda cols: cols[1] == "click") \
                    .map(lambda cols: (cols[0], 1))
result_rdd = clicks_rdd.reduceByKey(lambda a, b: a + b)
output = result_rdd.collect()

Execution Trace Solution

1. Narrow Transformation Trace (map & filter):

  • Partition A (Worker 1 - Rows 1-2): Emits [("user1", 1)] (Row 2 view event filtered out).
  • Partition B (Worker 2 - Rows 3-5): Emits [("user1", 1), ("user1", 1)] (Row 4 view event filtered out).

2. Wide Transformation Shuffle (reduceByKey):

  • Partitioner formula: Partition = username_last_digit % 2.
  • user1 (1 % 2 = 1) routes to Partition 1 (Worker 2).
  • Worker 1 sends ("user1", 1) over TCP to Worker 2.
  • Worker 2 retains its local tuples [("user1", 1), ("user1", 1)] locally without network transfer.

3. Aggregation & Driver Action (collect):

  • Worker 2 (Partition 1) aggregates: 1 + 1 + 1 = 3 Produces ("user1", 3).
  • Driver Node calls .collect(), pulling partition arrays across the network into the driver terminal:
[('user1', 3)]
Find this content helpful? ☕ Buy me a coffee

Entity Details

Create New Item

celebration
Enjoying the free content?

Create a free account to track your progress and save your place.

Create Free Account
help

Submit Technical Query

Have a question or run into an issue? Describe it below, upload an optional screenshot, and our engineering team will answer it!

image Attach image (optional)

Submit Feedback

build Free Developer Utility Free Tool
gavel

Privacy & Legal Disclaimer

1. Client-Side Browser Processing

All utility tools on DeepEngineerHub (including Image to PDF, Text Formatters, JSON Converters, and Encryptors) execute 100% locally within your client browser using WebAssembly and JavaScript. No uploaded images, text, or documents are transmitted, collected, or stored on remote servers.

2. Limitation of Liability ("As-Is" Provision)

Tools and services are provided free of charge for convenience and educational purposes "as-is" without warranties of any kind. DeepEngineerHub shall not be held liable for any data loss, formatting inconsistencies, or indirect damages resulting from tool usage.

3. Open Source & Third-Party Software

Certain utilities utilize open-source client libraries (such as jsPDF, Mermaid.js, Pyodide) licensed under MIT, Apache, or BSD open licenses. All intellectual property remains with their respective copyright holders.